﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;

namespace TestNetworkStream
{
    public class Server
    {
        public static void Run()
        {
            TcpListener list =
                new TcpListener(new IPEndPoint(IPAddress.Loopback, 5678));

            list.Start();

            TcpClient tcpcl = list.AcceptTcpClient();

            NetworkStream ns = tcpcl.GetStream();
            BinaryReader br = new BinaryReader(ns);
            BinaryWriter bw = new BinaryWriter(ns);

            while (true)
            {
                string msg = br.ReadString();

                Console.WriteLine("Got message: {0}", msg);

                bw.Write(msg);
            }
        }
    }
}
